<template>
<div id="eventManager">
  <v-header title="开发者审核" :showDownloadBtn = "download" :saveShow = "save"></v-header>
  <div class="container_wrap">
  <el-container class="container-box">
    <el-main class="main-table-box" style="margin-top:0px">
      <!-- 表单 -->
      <el-table
        ref="table"
        :data="tableData"
        tooltip-effect="dark"
        style="width: 100%">
        <el-table-column type="index" width="50"></el-table-column>
        <el-table-column
          label="开发者名称"
          width="auto">
          <template slot-scope="scope">
            {{scope.row.DEV.devName}}
          </template>
        </el-table-column>
        <el-table-column
          label="开发者id"
          width="auto">
          <template slot-scope="scope">
            {{scope.row.DEV.devId}}
          </template>
        </el-table-column>
        <el-table-column
          label="应用名称"
          width="auto">
          <template slot-scope="scope">
            {{scope.row.APP ? scope.row.APP.appName : ''}}
          </template>
        </el-table-column>
        <el-table-column
          prop="ent_name"
          label="应用代码"
          width="auto">
          <template slot-scope="scope">
            {{scope.row.APP ? scope.row.APP.appId : ''}}
          </template>
        </el-table-column>
        <el-table-column
          label="审核类型"
          width="auto">
           <template slot-scope="scope">
             {{auditTransDict[scope.row.auditTransId]}}
          </template>
        </el-table-column>
        <el-table-column label="操作">
              <template slot-scope="scope">
                <el-button type="text" size="small"  @click="handleEdit(scope.row)">审核</el-button>
              </template>
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <el-pagination
          @current-change="handleCurrentChange"
          :current-page="currentPage"
          :page-size="pagesize"
          layout="total, prev, pager, next"
          :total="totalCount"
          style="padding:20px 5px">
        </el-pagination>
    </el-main>
  </el-container>
  </div>
  <!-- 新增/编辑-弹窗 -->
    <el-dialog :title="addRoleDialogMode === 'ADD' ? '应用审核' : 'api审核'"
               :visible.sync="addRoleDialogVisiable"
               v-model="addRoleDialogMode"
               @close="cancel"
               width="900px"
               >
      <el-form :model="ruleForm"  ref="ruleForm" label-width="140px" class="demo-ruleForm">
    <div v-if="showform">
        <div>账户信息</div>
        <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="开发者名称" prop="devName">
          <el-input v-model="ruleForm.devName" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="开发者账户" prop="devAcct">
          <el-input v-model="ruleForm.devAcct" readonly></el-input>
        </el-form-item>
        </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="联系人邮箱" prop="linkEmail">
            <el-input v-model="ruleForm.linkEmail" readonly></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="联系人手机号" prop="linkMobile">
            <el-input v-model="ruleForm.linkMobile" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <div>
        <div>企业信息</div>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="企业名称" prop="ent_name">
            <el-input v-model="ruleForm.ent_name" readonly ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业证件号" prop="id_no">
            <el-input v-model="ruleForm.id_no" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row :gutter="24">
          <el-col :span="12">
            <el-form-item label="企业法人名称" prop="legal_name">
            <el-input v-model="ruleForm.legal_name" readonly ></el-input>
            </el-form-item>
          </el-col>
          <el-col :span="12">
            <el-form-item label="企业法人证件号码" prop="legal_id_no">
            <el-input v-model="ruleForm.legal_id_no" readonly></el-input>
            </el-form-item>
          </el-col>
        </el-row>
    </div>
    </div>
  <div v-if="showformlist">
        <div>开发者信息</div>
        <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="开发者账户" prop="devAcct">
          <el-input v-model="ruleForm.devAcct" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="联系人邮箱" prop="linkEmail">
          <el-input v-model="ruleForm.linkEmail" readonly></el-input>
        </el-form-item>
        </el-col>
        </el-row>
        <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="联系人手机号" prop="linkMobile">
          <el-input v-model="ruleForm.linkMobile" readonly></el-input>
          </el-form-item>
        </el-col>
        </el-row>
        <div>应用信息</div>
        <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="应用名称" prop="appName">
          <el-input v-model="ruleForm.appName" readonly></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="12">
          <el-form-item label="应用上线申请时间" prop="applyTime">
          <el-input v-model="ruleForm.applyTime" readonly></el-input>
          </el-form-item>
        </el-col>
        </el-row>
         <div>应用环境</div>
        <el-row :gutter="24">
        <el-col :span="12">
          <el-form-item label="应用加签公钥" prop="appPublicKeye">
          <el-input type="textarea"  :autosize="{ minRows: 2, maxRows: 4}" v-model="ruleForm.appPublicKey" readonly></el-input>
          </el-form-item>
        </el-col>
        </el-row>
  </div>
        <el-form-item class="dialogbtn">
          <el-button type="primary" @click="toPass('ruleForm')">审核通过</el-button>
          <el-button @click="toReject('ruleForm')">审核打回</el-button>
        </el-form-item>
      </el-form>
    </el-dialog>
</div>
</template>

<script>
  import { gateWay } from '../../dict/rule-dict'
  import '../../../../assets/css/mixinParameterManager.styl'
  import ajax from '../../../../api/ajax/ajax'
  import { getDateTime } from '../../../../assets/js/index'
  import {VHeader} from '../../../../components'
  import api from '../../../../api/url'
  // import {cnValidator} from '../../../../assets/js/rules'
export default{
  name: 'system-list',
  components: {
    VHeader
  },
  data () {
      return {
        tableLoading: true,
        condition: '', // 输入条件
        addRoleDialogVisiable: false,
        editdialogform: false,
        currentPage: 1, // 当前页码
        pagesize: 10, // 默认每页数据量
        totalCount: 0, // 默认数据总数
        editmetaid: false, // meta_id input框禁止修改
        editsysid: false, // event_id input框禁止修改
        showform: false,
        showformlist: false,
        tableData: [],
        checkbox: [],
        varlist: '',
        addRoleDialogMode: 'ADD', // 对话框色对话框模式  ADD新增 MODIFY 修改
        list: [],
        nassj: [],
        download: false,
        save: false,
        devPasswd: '',
        applyTime: '',
        closeTime: '',
        devId: '',
        devStatus: '',
        lastedTime: '',
        openTime: '',
        ruleForm: {
          devName: '',
          devBranch: '',
          devType: '',
          devAcct: '',
          linkName: '',
          linkMobile: '',
          applyTime: '',
          linkTelephone: '',
          linkEmail: '',
          ent_name: '',
          id_no: '',
          legal_name: '',
          legal_id_no: '',
          auditId: ''
        },
        currentItem: {}
      }
    },
    created () {
      this.queryForPage()
    },
    methods: {
      // 每页显示条目个数
      queryForPage (pageNum = 1, pageSize = 10) {
        ajax.post(api.SELECT_WAITACUDIT_DEV + '?' + 'pageNum=' + pageNum + '&pageSize=' + pageSize, {}).then((res) => {
          this.tableLoading = false
          this.tableData = []
          this.tableData = res.list
          this.totalCount = res.total
        })
      },
      // 当前页数
      handleCurrentChange (val) {
        this.queryForPage(val)
        this.varlist = val
      },
      // 关闭
      cancel (formName) {
        // this.$refs.ruleForm.clearValidate()
        // this.ruleForm = {}
        this.$refs.ruleForm.resetFields() // 移除校验 重置为初始状态
        this.addRoleDialogVisiable = false
        this.editdialogform = false
        this.ruleForm = this.currentItem
      },
      // 审核
      handleEdit (row) {
            this.addRoleDialogVisiable = true // 显示弹框
            this.editmetaid = true // devName input框禁止修改
            this.editsysid = true // devBranch input框禁止修改
            if (row.auditTransId === 'applyDevAcctAudit') {
              this.addRoleDialogMode = 'ADD'
              this.showform = true
              this.showformlist = false
              this.currentItem = JSON.parse(row.auditData)
              this.ruleForm = JSON.parse(row.auditData)
            } else if (row.auditTransId === 'applyDevAppAuthLinkAudit' || 'applyDevAppAudit') {
              this.addRoleDialogMode = 'MODIFY'
              this.showform = false
              this.showformlist = true
              var abj = {
                devAcct: row.DEV.devAcct,
                linkEmail: row.DEV.linkEmail,
                linkMobile: row.DEV.linkMobile,
                appName: row.APP.appName,
                applyTime: getDateTime(new Date(row.APP.applyTime), 'day'),
                appPublicKey: row.APP.appPublicKey
              }
              this.currentItem = abj
              this.ruleForm = abj
            }
              this.ruleForm.auditId = row.auditId
      },
      // 审核提交
      toPass () {
           const auditdata = {
             auditId: this.ruleForm.auditId
           }
        ajax.post(api.PASSAUDIT_DEV, auditdata, true).then((res) => {
            this.tableLoading = false
          if (res === 'success') {
            this.$message({
              type: 'success',
              message: '审核成功'
            })
            this.handleCurrentChange(this.varlist ? this.varlist : 1)
          }
        }).catch((err) => {
          if (err.errorMsg) {
            this.$message.error(err.errorMsg)
          }
        })
        this.addRoleDialogVisiable = false
      },
      // 审核打回
      toReject () {
           const auditlist = {
             auditId: this.ruleForm.auditId
           }
        ajax.post(api.REJECT_AUDIT_DEV, auditlist, true).then((res) => {
            this.tableLoading = false
          if (res === 'success') {
            this.$message({
              type: 'err',
              message: '审核拒接'
            })
            this.handleCurrentChange(this.varlist ? this.varlist : 1)
          }
        }).catch((err) => {
          if (err.errorMsg) {
            this.$message.error(err.errorMsg)
          }
        })
        this.addRoleDialogVisiable = false
      }
    },
    computed: {
      auditTransDict () {
        return gateWay.auditTransIds
      }
    }
}
</script>
